<%--
  Created by IntelliJ IDEA.
  User: RaIh
  Date: 2020/9/10
  Time: 15:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>后台系统管理</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <link rel="icon" href="/static/images/zlkt.ico" type="image/x-icon"/>
    <script src="/static/common/common.js"></script>
</head>
<body class="login-bg" style="background-image: url('/static/images/bgi.jpg')">

<div class="login">
    <div class="message">登录管理</div>
    <div id="darkbannerwrap"></div>

    <form method="post" class="layui-form" id="login">
        <input id="username" placeholder="用户名" value="root"  type="text" lay-verify="required" class="layui-input" >
        <hr class="hr15">
        <input id="password" lay-verify="required" value="123456" placeholder="密码"  type="password" class="layui-input">
        <hr class="hr15">
        <div>
            <input autocomplete="off" id="captcha" placeholder="验证码" type="text" class="layui-input" style="width: 180px;float: left">
            <img id="captcha_img" src="/static/images/code.jpg" style="cursor: pointer;width: 140px;height: 50px;float: right"/>
            <input type="hidden" value="{{.captcha.Id}}" id="captcha_id">
        </div>
        <hr class="hr15">
        <input value="登录" lay-submit lay-filter="login" style="width:100%;" type="button" id="btn">
        <hr class="hr20" >
        <span id="error" style="color: red"></span>
    </form>
</div>

<script>
    $(document).keyup(function (event) {
        if (event.keyCode == 13) {
            $("#btn").click()
        }
    })
    //如果发生了页面嵌套，刷新页面
    if (window.parent != window) {
        window.parent.location.reload(true)
    }

    // $("#captcha_img").attr("src",{{.captcha.BS64}});

    $("#captcha_img").click(getCaptcha);

    function getCaptcha() {
        $.ajax({
            url:"/change_captcha",
            data:{},
            type:"GET",
            success:function (data) {
                if (data.code != 200) {
                    alert(data.msg)
                } else {
                    $("#captcha").val("")
                    $("#captcha_img").attr("src",data.captcha.BS64);
                    $("#captcha_id").attr("value",data.captcha.Id);
                }
            },

        })
    }
    // $(document).ready(function(){
    //     $(document).keyup(function(event){
    //         if(event.keyCode == 13){
    //             dologin();
    //         }
    //     })
    // })
    $(function  () {

        layui.use('form', function(){
            var form = layui.form;

            form.on('submit(login)', function(data){
                // alert(888)
                var username = $("#username").val();
                var password = $("#password").val();
                $.ajax({
                    url: "/loginCheck",
                    type: "POST",
                    data:{
                        "username":username,
                        "password":password,
                    },
                    success:function (data) {
                        if(data == 'OK'){
                            //如果登录成功
                            location.href='index';
                        }else {
                            $("#error").html("登录失败，请检查用户名和密码");
                        }
                    },
                    error:function () {

                    }
                })
                // layer.msg(JSON.stringify(data.field),function(){
                //     location.href='index.html'
                // });
                // return false;
            });
        });
    })
</script>


<!-- 底部结束 -->

</body>
</html>